package com.showcal.platform.biz;


import com.showcal.platform.domain.ImSignModel;
import com.showcal.platform.request.IMLoginRequest;
import com.showcal.platform.response.IMLoginResponse;
import com.showcal.platform.utils.LoginSH256Util;
import com.xiniunet.framework.security.Passport;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by guzhixiong on 2015/11/12.
 */
public class WukongIMManagerImpl implements WuKongIMManager {
    /***
     * domain信息
     */
    public static final String domain = "showcal";

    /***
     * server端的 appToken信息
     */
    public static final String appToken = "SPoEHlw9zbytI068GJ0OMKWYQpjWiDjP";
    /***
     * appkey与appsecret的对应
     */
    public static Map<String, String> appkeys = new HashMap<String, String>();
    /***
     * 设备类型与appkey的对应
     */
    public static Map<String, String> devkeys = new HashMap<String, String>();

    @Override
    public IMLoginResponse IMLogin(IMLoginRequest request, Passport passport) {
        String appKey = getAppKeyByDevType(request.getDevType());
        String appSecret =getAppSecret(appKey);
        Long openId = passport.getUserId();
        ImSignModel imSignModel = LoginSH256Util.getLoginModel(appKey, appSecret, openId);
        IMLoginResponse response = new IMLoginResponse();
        response.setImSignModel(imSignModel);
        return response;
    }



    static {
        appkeys.put("ce2a020e4f400c0133cf91d76163685f", "S669mLAgOy1irlo60Ik96hRDWBoom6xj"); //android
        appkeys.put("ed040b5d9fadd53e09e61c6aa12fa0c5", "SUSL4Ha65OefgLTsh13FL5jDgTHL1lYA"); //ios
        appkeys.put("84d0b029b21c28e17a969edc19c85f49", "S6MFu6o4dN6e3qCmh5Dm0cxGEgMq2kzJ"); //web
    }

    static {
        devkeys.put("android", "ce2a020e4f400c0133cf91d76163685f"); //android
        devkeys.put("ios", "ed040b5d9fadd53e09e61c6aa12fa0c5"); //ios
        devkeys.put("web", "84d0b029b21c28e17a969edc19c85f49"); //web

        LoginSH256Util.setDomain(domain);
        LoginSH256Util.setAppToken(appToken);
    }

    /**
     * 获取appkey对应的appsecret信息
     * @desc
     * @param appKey
     * @return
     */
    public static String getAppSecret(String appKey) {
        return appkeys.get(appKey);
    }

    public static String getAppSecretByDevType(String devType) {
        String appKey = devkeys.get(devType);
        return getAppSecret(appKey);
    }

    public static String getAppKeyByDevType(String devType) {
        return devkeys.get(devType);
    }
}
